Skip to content
This repository was archived by the owner on Jun 1, 2026. It is now read-only.

Transaction state - #1104

Merged
0xSou merged 12 commits into
mainfrom
trans-state
May 5, 2026
Merged

0xSou merged 12 commits into
mainfrom
trans-state

Conversation

@0xSou

@0xSou 0xSou commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

No description provided.

0xSou added 4 commits April 29, 2026 22:44
Introduce a new JobConfiguration type for job backoff/timing settings. The struct (crates/primitives/src/job_configuration.rs) derives Debug/Clone/Copy/PartialEq and implements Serialize/Deserialize, uses serde camelCase and typeshare(swift = "Sendable"). Update crates/primitives/src/lib.rs to expose the new module and re-export JobConfiguration.
Add InTransit transaction status across primitives and remote swap types, and wire swap-aware status resolution into the gateway. Introduces TransactionSwapMetadata to transaction metadata, adds Swapper/SwapperProvider usage, and replaces the old TransactionStatusClient with a new StatusProvider that delegates to chain providers or the swapper as appropriate. Includes timeout handling and mapping of swap results into TransactionUpdate, plus related model and import adjustments.
@0xSou 0xSou self-assigned this Apr 30, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the gateway logic by introducing a ChainClientFactory and a StatusProvider to handle transaction status updates, including new support for swap-specific statuses, an InTransit state, and transaction timeout logic. Feedback includes resolving a name collision and type mismatch in the transaction state configuration, replacing risky unwrap() calls with proper error handling, and making hardcoded API keys configurable.

@@ -0,0 +1,22 @@
use primitives::{Chain, JobConfiguration};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

There is a name collision between the imported primitives::JobConfiguration and the local JobConfiguration struct defined on line 8. This will cause a compilation error. Since you are redefining the struct for UniFFI mapping, you should remove it from the import list.

Suggested change
use primitives::{Chain, JobConfiguration};
use primitives::Chain;

pub fn transaction_state_config(chain: Chain) -> JobConfiguration {
let block_time_ms = chain.block_time();
JobConfiguration {
initial_interval_ms: block_time_ms.clamp(1, INITIAL_CAP_MS),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This line will likely fail to compile due to a type mismatch. block_time_ms is typically an i64, while INITIAL_CAP_MS is a u32. Additionally, the result of clamp needs to be cast to u32 to match the initial_interval_ms field type.

Suggested change
initial_interval_ms: block_time_ms.clamp(1, INITIAL_CAP_MS),
initial_interval_ms: block_time_ms.clamp(1, INITIAL_CAP_MS as i64) as u32,

Ok(Arc::new(HyperCoreClient::new_with_preferences(alien_client, preferences, secure_preferences)))
}
Chain::Bitcoin | Chain::BitcoinCash | Chain::Litecoin | Chain::Doge | Chain::Zcash => {
Ok(Arc::new(BitcoinClient::new(alien_client, BitcoinChain::from_chain(chain).unwrap())))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using unwrap() here is risky. If a new chain is added to the match arm but is not supported by BitcoinChain::from_chain, the application will panic at runtime. It's safer to handle the potential error by returning a GatewayError::PlatformError.

Suggested change
Ok(Arc::new(BitcoinClient::new(alien_client, BitcoinChain::from_chain(chain).unwrap())))
Ok(Arc::new(BitcoinClient::new(alien_client, BitcoinChain::from_chain(chain).ok_or(GatewayError::PlatformError { msg: format!("Unsupported bitcoin chain: {:?}", chain) })?)))

Ok(Arc::new(CosmosClient::new(CosmosChain::from_chain(chain).unwrap(), alien_client)))
}
Chain::Ton => Ok(Arc::new(TonClient::new(alien_client))),
Chain::Tron => Ok(Arc::new(TronClient::new(alien_client.clone(), TronGridClient::new(alien_client.clone(), String::new())))),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The TronGridClient is initialized with an empty string for the API key. This will likely lead to rate limiting or authentication errors when interacting with TronGrid. Consider making the API key configurable via preferences or environment variables.

pub api_client: GemApiClient,
chain_factory: Arc<ChainClientFactory>,
yielder: Yielder,
status_provider: StatusProvider,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move status provider out of this?

}
}

fn apply_timeout(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never use apply in the code

0xSou added 6 commits May 4, 2026 12:24
Introduce TransactionState::is_completed() to centralize logic for which states are terminal. Replace a manual match in gemstone/src/transaction_state/status_provider.rs with a call to is_completed(), simplifying the expired->Failed decision and improving readability while preserving existing behavior.
Switch status_provider to ms throughout: timestamp_millis() for now, no /1000 on chain_transaction_timeout, drop u64 casts. Update Hyperliquid start_time accordingly. Use existing From<GemTransactionStateRequest> for the chain provider call. Add tests for get_transaction_update and TransactionState::is_completed.
Remove the shared JobConfiguration type from crates/primitives (deleted job_configuration.rs and removed its mod/use exports). Introduce a local GemJobConfiguration in gemstone/src/transaction_state/config.rs (derive uniffi::Record) and update transaction_state_config to return GemJobConfiguration instead of the removed shared type. Logic and constants are unchanged; this decouples the uniFFI-record type from the primitives crate.
@0xSou
0xSou marked this pull request as ready for review May 5, 2026 09:26
@@ -0,0 +1,22 @@
use primitives::Chain;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should live in another crate, so it could be used by other services inside core, not just iOS/Android

0xSou added 2 commits May 5, 2026 20:52
Move job timing constants and logic into primitives::JobConfiguration and add JobConfiguration::transaction_state(chain) to compute initial_interval_ms, max_interval_ms and step_factor. Remove duplicate constants and construction from gemstone::transaction_state::config, and make gemstone build GemJobConfiguration from the shared JobConfiguration. This reduces duplication and ensures consistent transaction-state timing behavior across crates.
@0xSou
0xSou merged commit 4d14fc4 into main May 5, 2026
6 checks passed
@0xSou
0xSou deleted the trans-state branch May 5, 2026 18:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants